import Vue from 'vue'
import Router from 'vue-router'
import example from './example'

const layout = () => import('../components/layout/layout'),
    exampleLayout = () => import('../components/layout/example-layout'),
    provide = () => import('../page/busServer/provide'),
    atomicService = () => import('../page/busServer/atomic-service'),
    consumer = () => import('../page/busServer/consumer'),
    serviceSimulation = () => import('../page/busServer/serviceSimulation'),
    importExport = () => import('../page/busServer/import-export'),
    systemInformation = () => import('../page/busServer/system-information'),
    serviceCatalogue = () => import('../page/busServer/service-catalogue'),
    busInstance = () => import('../page/busServer/bus-instance'),
    apiPackage = () => import('../page/busServer/api-package'),
    apiPackageDetail = () => import('../page/busServer/api-package-detail'),
    scriptPackage = () => import('../page/busServer/script-package'),
    scriptPackageDetail = () => import('../page/busServer/script-package-detail'),
    monIndex = () => import('../page/monitoring/mon-index'),
    atomicServiceList = () => import('../page/monitoring/atomic-service-list'),
    serverList = () => import('../page/monitoring/serverList'),
    aPIEditor = () => import('../page/monitoring/api-editor'),
    newAPIEditor = () => import('../page/monitoring/new-api-editor'),
    newAPIAudit = () => import('../page/monitoring/new-api-editor'),
    aPIAudit = () => import('../page/monitoring/api-audit'),
    logQuery = () => import('../page/monitoring/logQuery'),
    userManagement = () => import('../page/monitoring/userManagement'),
    serverListDetails = () => import('../page/monitoring/serverListDetails'),
    logDetails = () => import('../page/monitoring/logDetails'),
    // index = () => import('../page/my/index'),
    login = () => import('../page/login'),
    consumerAnalysis = () => import('../page/monitoring/consumer-analysis'),
    serviceAnalysis = () => import('../page/monitoring/service-analysis'),
    // 初始路由集
    constantRouterMap = [
        {
            path: '/401',
            name: '401',
            component: layout
        },
        {
            path: '/login',
            name: '登录',
            component: login
        },
        {
            path: '/',
            name: 'index',
            component: layout,
            children: [
                {
                    path: '/provide',
                    name: 'provide',
                    component: provide,
                    meta: {
                        title: '服务提供者',
                        parent: 'index'
                    }
                },
                {
                    path: '/systemInformation',
                    name: 'systemInformation',
                    component: systemInformation,
                    meta: {
                        title: '服务提供者',
                        parent: 'index'
                    }
                },
                {
                    path: '/atomicService',
                    name: 'atomicService',
                    component: atomicService,
                    meta: {
                        title: '原子服务',
                        parent: 'index'
                    }
                },
                {
                    path: '/serviceCatalogue',
                    name: 'serviceCatalogue',
                    component: serviceCatalogue,
                    meta: {
                        title: '服务目录',
                        parent: 'index'
                    }
                },
                {
                    path: '/consumer',
                    name: 'consumer',
                    component: consumer,
                    meta: {
                        title: '消费者服务',
                        parent: 'index'
                    }
                },
                {
                    path: '/busInstance',
                    name: 'busInstance',
                    component: busInstance,
                    meta: {
                        title: '总线实例',
                        parent: 'index'
                    }
                },
                {
                    path: '/apiPackage',
                    name: 'apiPackage',
                    component: apiPackage,
                    meta: {
                        title: '封装管理',
                        parent: 'index'
                    }
                },
                {
                    path: '/apiPackage/detail',
                    name: 'apiPackageDetail',
                    component: apiPackageDetail,
                    meta: {
                        title: '接口详情',
                        parent: 'index'
                    }
                },
                {
                    path: '/scriptPackage',
                    name: 'scriptPackage',
                    component: scriptPackage,
                    meta: {
                        title: '脚本管理',
                        parent: 'index'
                    }
                },
                {
                    path: '/scriptPackage/detail',
                    name: 'scriptPackageDetail',
                    component: scriptPackageDetail,
                    meta: {
                        title: '脚本详情',
                        parent: 'index'
                    }
                },
                {
                    path: '/serviceSimulation',
                    name: 'serviceSimulation',
                    component: serviceSimulation,
                    meta: {
                        title: '服务模拟',
                        parent: 'index'
                    }
                },
                {
                    path: '/importExport',
                    name: 'importExport',
                    component: importExport,
                    meta: {
                        title: '导入导出',
                        parent: 'index'
                    }
                }
            ]
        },
        {
            path: '/monitoring',
            name: 'monitoring',
            component: layout,
            children: [
                {
                    path: '/index',
                    name: 'monIndex',
                    component: monIndex,
                    meta: {
                        title: '首页',
                        parent: 'monitoring'
                    }
                },
                {
                    path: '/serverList',
                    name: 'serverList',
                    component: serverList,
                    meta: {
                        title: '服务清单',
                        parent: 'monitoring'
                    },
                    children: [
                        {
                            path: 'serverListDetails',
                            name: 'serverListDetails',
                            component: serverListDetails,
                            meta: {
                                title: '详情'
                            }
                        }
                    ]
                },
                {
                    path: '/atomicServiceList',
                    name: 'atomicServiceList',
                    component: atomicServiceList,
                    meta: {
                        title: '原子服务清单',
                        parent: 'monitoring'
                    }
                },
                {
                    path: '/consumerAnalysis',
                    name: 'consumerAnalysis',
                    component: consumerAnalysis,
                    meta: {
                        title: '消费者分析',
                        parent: 'monitoring'
                    }
                },
                {
                    path: '/serviceAnalysis',
                    name: 'serviceAnalysis',
                    component: serviceAnalysis,
                    meta: {
                        title: '服务分析',
                        parent: 'monitoring'
                    }
                },
                {
                    path: '/logQuery',
                    name: 'logQuery',
                    component: logQuery,
                    meta: {
                        title: '日志查询',
                        parent: 'monitoring'
                    },
                    children: [
                        {
                            path: 'logDetails',
                            name: 'logDetails',
                            component: logDetails,
                            meta: {
                                title: '详情'
                            }
                        }
                    ]
                },
                {
                    path: '/userManagement',
                    name: 'userManagement',
                    component: userManagement,
                    meta: {
                        title: '用户管理',
                        parent: 'monitoring'
                    }
                },
                {
                    path: '/aPIEditor',
                    name: 'aPIEditor',
                    component: aPIEditor,
                    meta: {
                        title: 'API编辑',
                        parent: 'monitoring'
                    },
                    children: [
                        {
                            path: 'newAPIEditor',
                            name: 'newAPIEditor',
                            component: newAPIEditor,
                            meta: {
                                title: '编辑'
                            }
                        }
                    ]
                },
                {
                    path: '/aPIAudit',
                    name: 'aPIAudit',
                    component: aPIAudit,
                    meta: {
                        title: 'API审核',
                        parent: 'monitoring'
                    },
                    children: [
                        {
                            path: 'newAPIEditor',
                            name: 'newAPIAudit',
                            component: newAPIAudit,
                            meta: {
                                title: '审核'
                            }
                        }
                    ]
                }
            ]
        }
    ]

/*
* 开发环境添加example示例路由，可跳转查看组件如何使用
* 上线时将这一段注释
*/
if (process.env.NODE_ENV !== 'production') {
    constantRouterMap.push({
        path: '/example',
        name: 'example',
        component: exampleLayout,
        meta: {
            title: '控件示例'
        },
        children: []
    })
    constantRouterMap[constantRouterMap.length - 1].children.unshift(...example)
}

let router = new Router({
    mode: 'history',
    routes: constantRouterMap
})

// 路由跳转前更改网页标题
router.beforeEach((to, from, next) => {
    // 页面跳转更改浏览器标题
    // if (to.meta && to.meta.title) {
    //     document.title = to.meta.title
    // }
    next()
})

Vue.use(Router)

export default router
